
package de.swta.freezay.database.wicketAdapter;

import de.swta.freezay.database.JPAController;
import de.swta.freezay.database.dbEntities.Reservation;
import java.util.Iterator;
import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
import org.apache.wicket.model.IModel;

/**
 * A SortableDataProvider for reservation entities
 *
 * @author Christian Baeumer
 * @see SortableDataProvider
 */
public class ReservationDataProvider extends SortableDataProvider<Reservation>{

    public ReservationDataProvider() {
        setSort("reservationNr", true);
    }

    @Override
    public Iterator<? extends Reservation> iterator(int first, int count) {
        SortParam sp = getSort();

        return JPAController.ReservationJpaController.findReservationEntities(
                count, first, sp.getProperty(), sp.isAscending()).iterator();
    }

    @Override
    public int size() {
        return JPAController.ReservationJpaController.getReservationCount();
    }

    @Override
    public IModel<Reservation> model(Reservation r) {
        return new DetachableReservationModel(r);
    }

    @Override
    public void detach() {
    }

}